package org.alala.datamodels.common.query;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashSet;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CompareMethodDef {

	private static Logger logger = LoggerFactory.getLogger(CompareMethodDef.class);
	
	public static final String EQUAL = "equal";
	
	public static final String NOT_EQUAL = "not_equal";
	
	public static final String LESS = "less";
	
	public static final String LESS_EQUAL = "less_equal";
	
	public static final String LARGER = "larger";
	
	public static final String LARGER_EQUAL = "larger_equal";
	
	public static final String START_WITH = "start_with";
	
	public static final String END_WITH = "end_with";
	
	public static final String CONTAINS = "contains";
	
	public static final String IN = "in";
	
	private static Set<String> values;
	
	static {
		values = new HashSet<>();
		
		for(Field f : CompareMethodDef.class.getFields()) {
			int m = f.getModifiers();
			if(Modifier.isPublic(m) && Modifier.isStatic(m) && 
					Modifier.isFinal(m) && f.getType().equals(String.class)) {
				Object value;
				try {
					value = f.get(null);
					if(value != null) {
						values.add(value.toString());
					}
				} catch (IllegalArgumentException e) {
					logger.error("init compare method set error", e);
				} catch (IllegalAccessException e) {
					logger.error("init compare method set error", e);
				}
			}
		}
	}
	
	public static boolean isValid(String value) {
		return values.contains(value);
	}
	
}
